package com.xiaolin.sports.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xiaolin.sports.dao.CollectionRecordMapper;
import com.xiaolin.sports.dao.CourseInfoMapper;
import com.xiaolin.sports.model.CollectionRecord;
import com.xiaolin.sports.service.ICollectionService;
import com.xiaolin.sports.view.CourseListView;

@Service("collectionService")
public class CollectionServiceImpl implements ICollectionService {

	@Autowired
	private CourseInfoMapper courseInfoMapper;
	@Autowired
	private CollectionRecordMapper collectionRecordMapper;
	
	@Override
	public int addAndUpdate(CollectionRecord record) {
		if(record.getId() == null) {
			return collectionRecordMapper.insertSelective(record);
		}
		return collectionRecordMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public List<CourseListView> selectListForCollection(String openid, Integer parentId) {
		return courseInfoMapper.selectListForCollection(openid, parentId);
	}

	@Override
	public CollectionRecord selectByParam(CollectionRecord record) {
		return collectionRecordMapper.selectByParam(record);
	}

}
